Fix fee estimation APIs: bounded waitTime estimate, consistent with getFee (#1884) - #2450
Fix fee estimation APIs: bounded waitTime estimate, consistent with getFee (#1884)#2450Ergologica wants to merge 3 commits into
Conversation
|
Flagging this before a reviewer finds it and reasonably closes the PR: #1884 already has a merged PR saying Having read both diffs against each other, they are not the same change. #2410 (
This PR ( The clearest evidence they are complementary rather than competing: this branch merges clean on current master, and current master already contains #2410. It is built on top of that work. So my reading is that #1884 is in the same state as #1870 — a merged PR did part of it, the issue stayed open because part of it was left. But that is my reading of my own PR, so treat it accordingly; if you look and conclude #2410 was sufficient, say so and I will close this without argument. cc @glasgowm148 for the registry side — reservation is ErgoDevs/Ergo-Bounties#47, and I have written the general version of this up as ErgoDevs/Ergo-Bounties#60, since it is not the only entry in that state. |
Closes #1884
The problem
As reported in #1884,
/transactions/waitTimecould return absurd values (e.g. ~20 years for a 1 KB tx paying the minimal fee), while/transactions/getFeesimultaneously recommended a lower fee for a 2-minute confirmation. Two causes:getExpectedWaitTimeandgetRecommendedFeewere computed from unrelated data.getRecommendedFeeuses the mempool fee histogram (average fee of transactions taken from the pool, bucketed by how long they waited), whilegetExpectedWaitTimeusedposition_in_pool × elapsed / takenTxns, whereelapsedis the time since the start of the statistics measurement. The two could not be consistent with each other.ErgoMemPool#remove; when transactions get stuck,elapsedgrows without limit and the estimate diverges (the "20 years" effect). Additionally,MemPoolStatistics.measurementIntervalMsecwas set to60 * 1000(one minute) while the comment and the pruning logic (keep data up to 2*measurementIntervalMsec) clearly intend one hour.The fix
getExpectedWaitTimenow estimates the wait time from the same fee histogram used bygetRecommendedFee: the earliest wait-time bin whose average fee per KB does not exceed the queried transaction's fee per KB. This makes the two endpoints mutually consistent: a transaction payinggetFee(t)getswaitTime <= t(covered by a test).elapsedbounded by the statistics measurement window (2 × measurementIntervalMsec), so periods with no transactions taken from the pool can no longer produce unbounded estimates.measurementIntervalMsecfixed to one hour (60 * 60 * 1000), matching its documentation and the histogram design (60 one-minute bins).Testing
Four new tests in
ErgoMemPoolSpec(there was no fee-estimation coverage before, addressing the testing gap mentioned by @kushti in the issue):getRecommendedFeereturns the minimal fee when no statistics is collected;getRecommendedFeereturns the histogram average for the first non-empty bin;All tests pass locally with
sbt "testOnly org.ergoplatform.nodeView.mempool.ErgoMemPoolSpec".